﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

/* Keeps a look at what's on the screen. Can scroll, determines what viewable. */
namespace RoboTrocity {
	class Camera {
		Point origin; //the top-left of the viewable area
		Point destination; //where the camera wants to center on
		const int WIDTH = 800; //technically these are set by the window size.
		const int HEIGHT = 600;
		const int TOP_SPEED = 50;
		bool followOrders = true;

		public Camera() {
			origin = Point.Zero;
			destination = origin;
		}

		public void moveX(int xDist) {
			origin.X += xDist;
		}

		public void moveY(int yDist) {
			origin.Y += yDist;
		}

		public void centerOnPoint(Point point) {
			if (point.X - (WIDTH / 2) < 0) {
				point.X = WIDTH / 2;
			}
			if (point.Y - (HEIGHT / 2) < 0) {
				point.Y = HEIGHT / 2;
			}
			destination.X = point.X - WIDTH / 2;
			destination.Y = point.Y - HEIGHT / 2;
		}

		public void Update() {
			Point movement = Point.Zero;
			movement = destination - origin;
			if (Math.Abs(movement.X) > TOP_SPEED) {
				movement.X = TOP_SPEED * Math.Sign(movement.X);
			}
			if (Math.Abs(movement.Y) > TOP_SPEED) {
				movement.Y = TOP_SPEED * Math.Sign(movement.Y);
			}
			origin += movement;
		}

		public Point Origin {
			get { return origin; }
			set { origin = value; }
		}

		public Rectangle Bounds {
			get { return new Rectangle((int)origin.X, (int)origin.Y, WIDTH, HEIGHT); }
		}

		public bool isFollowingOrders {
			get { return followOrders; }
			set { followOrders = value; }
		}

	}
}
